package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.entity.Device;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceDataVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/iot")
@Api(tags = "设备管理")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    public ResponseResult syncProductList(){
        deviceService.queryProductList();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct(){
        List<ProductVo> list =deviceService.allProduct();
        return ResponseResult.success(list);
    }

    @PostMapping("/RegisterDevice")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    //查询分页列表
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto){
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(pageResponse);
    }

    //查找设备详情数据
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    //查询指定设备的物模型运行状态
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) throws Exception {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData data = deviceService.queryDevicePropertyStatus(request);
         return ResponseResult.success(data);
    }

    //查询指定产品的已发布物模型中的功能定义详情
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<Map<String,String>> queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request)throws Exception{
        Map<String,String> map = deviceService.queryThingModelPublished(request);
        return ResponseResult.success(map);
    }

    @PostMapping("/UpdateDevice")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto)throws Exception{
        deviceService.UpdateDevice(deviceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/DeleteDevice")
    public ResponseResult DeleteDevice(@RequestBody DeviceDto deviceDto)throws Exception{
        deviceService.DeleteDevice(deviceDto);
        return ResponseResult.success();
    }
}






















